const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../utils/user.js');

//index.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    add:[],
    nowadress:'',
    tz:[],
    name:''
  },
  go(){
    wx.navigateTo({
      url: '../ucenter/group/group',
    })
  },

  key(e){
    console.log(e)
    this.setData({
      name:e.detail.value
    })
  },

  tzresult(){
    this.setData({
      add:[]
    })
    let that = this
    if(that.data.name==''){
      that.allTz()
    }
    else{
    util.request(api.NearGroup, {
      name:that.data.name
    }, 'post', {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
        'X-Qxmall-Token': wx.getStorageSync('token')
      }).then(function (res) {
        console.log(res)
        const arr = res.data.leaderList
        const add=that.data.add
        add.push(arr)
        that.setData({
          tz:add
        })
        
      });
    }
  },

  backindex(e){
    console.log(e.currentTarget.dataset.name)
    wx.setStorageSync("name", e.currentTarget.dataset.name)
    wx.navigateBack({
      delta:1
    })
  },

  allTz() {
    let that = this
    util.request(api.QueryNearbyLeader, {
      lat: wx.getStorageSync('latitude'),
      lng: wx.getStorageSync('longitude')
    }, 'post', {
        'Content-Type': 'application/json;charset=UTF-8',
        'X-Qxmall-Token': wx.getStorageSync('token')
      }).then(function (res) {
        console.log(res)
        if(res.code==200){
          that.setData({
            tz: res.data.leaderList
          })
        }
      });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },
  selectedClick () {
    // 设置权限
    let that=this
        // 选择位置
        wx.chooseLocation({
          success: function (res) {
            console.log(res);
            that.setData({
              nowadress:res.address
            })
          },
        })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
      this.allTz()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})